<?php
/**
 * User: Hufeng
 * Date: 2017/08/29 19:48
 * Desc: 交易所Model
 */
namespace App\Model;
use SasPHP\SqlModel;

class TradePlaceModel extends SqlModel{
    protected $dbName = 'trade_place';

    public function __construct(){
        parent::__construct('DB_SERVER');
    }

    function insertData($data){
        $this->dbConn->insert($this->dbName,$data);
        return $this->dbConn->id();
    }

    function editData($where,$data){
        $this->dbConn->update($this->dbName,$data,$where);
    }

    function delData($data){
        $this->dbConn->delete($this->dbName, $data);
    }

    function findData($where,$fields='*'){
        $res = $this->dbConn->get($this->dbName,$fields,$where);
        return $res;
    }

    function queryData($where,$fields='*'){
        $res = $this->dbConn->select($this->dbName,$fields,$where);
        return $res;
    }
    //获取统计数据
    public function getTotalNum($where){
        $res = $this->dbConn->count($this->dbName,$where);
        return $res;
    }
    //sum数据
    public function sumData($where,$param){
        $res = $this->dbConn->sum($this->dbName,$param,$where);
        return $res;
    }
    //获取股票已开盘分钟数
    public function tradeBeginMin($tpId){
        $tpRes = $this->findData(['id'=>$tpId]);
        list($shour,$smin) = explode(':',$tpRes['stime']);
        $date = date('Y-m-d');
        $etime = $date.' '.$tpRes['etime'];
        if(time()>$etime){
            $tmin = ceil(($etime-strtotime($date))/60);
        }else{
            $tmin = ceil((time()-strtotime($date))/60);
        }
        $hbMin = $tmin - (($shour*60)+$smin);
        $hbMin = $hbMin>1 ? $hbMin : 1;
        return $hbMin;
    }

}
